﻿@{
	Layout = "~/Views/Shared/_Layout.cshtml";
}

@model Hangerd.Mvc.ViewModels.PagedListModel<dPet.Application.DataObjects.InventoryAlarmItemDto>

<div class="page-header">
	<h3>库存告警列表</h3>
</div>

<div class="panel panel-default">
	<div class="panel-heading">
		&nbsp;
	</div>
	<table class="table table-striped text-center">
		<thead>
			<tr>
				<th class="text-center">告警时间</th>
				<th class="text-center">商品条码</th>
				<th class="text-center">商品名称</th>
				<th class="text-center" width="120px">告警类型</th>
				<th class="text-center" width="320px">告警内容</th>
				<th class="text-center" width="160px">操作</th>
			</tr>
		</thead>
		<tbody>
			@foreach (var alarm in Model.List)
			{
				<tr>
					<td>@alarm.LastModified.ToString("yyyy-MM-dd HH:mm:ss")</td>
					<td>@alarm.ProductBarcode</td>
					<td>@alarm.ProductName</td>
					<td>@Hangerd.Utility.CommonTools.GetEnumDescription(alarm.AlarmType)</td>
					<td>@alarm.Detail</td>
					<td>
						<a href="javascript:;" onclick="disable_alarm('@alarm.ProductId', '@alarm.AlarmType', this)">不再提醒</a>
						&nbsp;&nbsp;
						<a href="@Url.Action("Index", "Product", new { id = alarm.ProductId })">修改阈值</a>
					</td>
				</tr>
			}
		</tbody>
	</table>
</div>

@HtmlUtil.BootstrapPager(Model.PageIndex, Model.PageSize, Model.TotalNumber, p => Url.Action("AlarmList", "Inventory", new { pageIndex = p }))

@section scripts {
	<script type="text/javascript">
		function disable_alarm(productId, alarmType, btn) {
			if (!confirm("是否关闭该告警（可在商品管理中重新开启）？"))
				return false;

			$.ajax({
				type: "POST",
				dataType: 'json',
				url: "/Inventory/DisableAlarm",
				data: {
					'productId': productId,
					'alarmType': alarmType
				},
				success: function (r, status) {
					alert(r.Message);

					if (r.Success) {
						$(btn).parent().parent().remove();
					}
				}
			});

		}
	</script>
}